package com.chixing.day09_innerclass;

public class StringDemo2 {
    public static void main(String[] args) {
        String s1  = "good";
        s1 = "hello";

        String s2 = new String("code");//堆
        String s3 = "code";   //字符串常量池
        System.out.println("s2 == s3?:"+(s2 == s3));//false


        String s4 = "file";
        String s5 = "file";
        System.out.println("s4 == s5?:"+ (s4 == s5));//true == 比较的是内存地址

        String s6 = new String("help");
        String s7 = new String("help");
        System.out.println("s6==s7?:"+(s6==s7));//false
        String s8 ="help";

        /*
            String s1 = "a";
            String s2 = "b";
                s1+s2===>new String("ab")堆
                s1.concat(s2)===>new String("ab")堆

                "a" + "b"===>在常量池中放一份"ab"
        */
        String str1 = "hello";
        String str2 = "world";
        String str0 = "hello"+"world";//"helloworld" 到常量池中匹配
        String str3 = str1 + str2;//等价于new String("helloworld")
        String str4 = "helloworld";
        String str5 = str1 + str2;//等价于new String("helloworld")

        System.out.println("str0 == str4?:"+(str0==str4));//true
        System.out.println("str3 == str0?:"+(str3==str0));//false
        System.out.println("str3 == str4?:"+(str3==str4));//false
        System.out.println("str3 == str5?:"+(str3==str5));//false

        String str6 = str1.concat(str2);//new String("helloworld")
        System.out.println("str3 == str6?:"+(str3==str6));//false



        String word = "Strings are constant; their values cannot be changed after they  are created";


    }
}
